
<%--                                                                       --%>
<%-- Copyright (c) 2004 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/bv-html.tld"      prefix="bvhtml" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld"  prefix="bean"   %>
<%@ taglib uri="/WEB-INF/struts-html.tld"  prefix="html"   %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"  %>


<script language="javascript" src="<%= request.getContextPath() %>/cs/js/date.js" type="text/javascript">
</script>
<script language="javascript" src="<%= request.getContextPath() %>/cs/js/stringFunc.js" type="text/javascript">
</script>



<script language="JavaScript">

//
// popup new window to find and select a user
//
function searchUserPopup(popupUrl, parentFormName) {

  var timestamp = getTimeStamp();

  if (popupUrl != null) {
    if (popupUrl.indexOf("?") < 0) {
      popupUrl += "?";
    } else {
      popupUrl += "&";
    }
  }

  popupUrl += 'timestamp=' + timestamp +
              '&parentFormName=' + parentFormName +
              '&doSearch=false';
                          
  var windowName = parentFormName;
  var windowFeatures = 'width=600,height=400,scrollbars=yes,resizable=yes';

  
  var popupWindow = window.open(popupUrl, windowName, windowFeatures);

  if ( popupWindow != null) {
    if( popupWindow.opener == null) {
      popupWindow.opener = self;
    }
  }
  popupWindow.focus();
}

function setUserData(formName, firstName, lastName, fullName, userAlias) {
  var theForm = document.forms[formName];
  if (theForm.isUsingFMLName.value == "true") {
    theForm.firstName.value = firstName;
    theForm.lastName.value = lastName;
  } else {
    theForm.fullName.value = fullName;  
  }
    
  theForm.userAlias.value = userAlias;
}
      
function onClickSave(theForm) {
  if (validateForm(theForm)) {
    theForm.submit();
  }
  
  return false;
}

function validateForm(theForm) {
   // check that the field is not more than 250 chars
   if ( theForm.description.value.length > 255 ) {
     alert('<bean:message  bundle="appCommonRes" key="ca.error.delegation.reason"/>');
     return false;
   }

   // check whether the delegation has started or not.
   var started = true;
   if (theForm.started.value != "true") {
    started = false;
   } 
   
   var endDate = getDateOnly("caDelegationEditForm", "end");
  
   var startDateOnly;
   if (started) {
     var year = theForm.elements['start.year'].value;
     var month = theForm.elements['start.month'].value;
     var day = theForm.elements['start.day'].value;
     startDateOnly = new Date(year, month, day, 0,0,0,0);
   }
   else { 
    startDateOnly = getDateOnly("caDelegationEditForm", "start");
    startDateOnly.setHours(0);
    startDateOnly.setMinutes(0);
    startDateOnly.setSeconds(0);
    startDateOnly.setMilliseconds(0);
   } 

   var today = new Date();
   today.setHours(0);
   today.setMinutes(0);
   today.setSeconds(0);
   today.setMilliseconds(0);
   
   if (!started) {
    if (today - startDateOnly > 0) {
      alert('<bean:message  bundle="appCommonRes" key="ca.error.delegation.startInPast"/>');
      return false;
    }
   }
   
   if (startDateOnly.getTime() > endDate.getTime())
   {
      alert('<bean:message  bundle="appCommonRes" key="ca.error.delegation.endBeforeStart"/>');
      return false;
   }
   
   if (!started) {
     var alias = stringTrim(theForm.userAlias.value);
     var emptyToField = false;
     if (theForm.isUsingFMLName.value == "true") {
       var firstName = stringTrim(theForm.firstName.value);
       var lastName = stringTrim(theForm.lastName.value);
       
       if ( (alias == null || alias == "") && (firstName == null || firstName == "") && (lastName == null || lastName == "") ) {
        emptyToField = true;           
       }
     }  
     else {
       var fullName = stringTrim(theForm.fullName.value); 
       if ( (alias == null || alias == "") && (fullName == null || fullName == "")) {
        emptyToField = true;                  
       } 
     }
     if (emptyToField) {
       alert('<bean:message  bundle="appCommonRes" key="ca.error.delegation.toField"/>'); 
       return false;
     }
   }
   return true;
}


//
// Create a dummy (timestamp) attribute to get around an IE cache problem.
//
function getTimeStamp() {
   var now = new Date;
   var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();
   return timestamp;
}


</script>


<!-- Zone 5 starts here.  -->

<html:form action="/ca/delegationSave.do">

<html:hidden property="isNew"/>
<html:hidden property="started"/>
<html:hidden property="isUsingFMLName"/>

<!-- Zone 5 starts here.  -->

<table class="zoneFive" width="100%" border="0" cellspacing="0" 
       cellpadding="0" 
       summary='<bean:message bundle="appCommonRes" key="ca.delegation.tableSummary"/>'>
  <tr>
    <td valign="top" width="100%">
        
      <div class="app_pageTitle">
        <logic:equal name="caDelegationEditForm" property="isNew" value="true">
          <bean:message bundle="appCommonRes" key="ca.delegation.addNew"/>
        </logic:equal>
        <logic:equal name="caDelegationEditForm" property="isNew" value="false">
          <bean:message bundle="appCommonRes" key="ca.delegation.edit"/>
          <html:hidden property="delegationOid"/>
        </logic:equal>  
      </div>
			
			<div class="blockWrap">
			  
      <div class="errorMessage">
        <html:errors/>
        <logic:equal name="caDelegationEditForm" property="matchedUser" value="-1">
          <bean:message bundle="appCommonRes" key="ca.error.delegation.nomatch"/>
        </logic:equal>
        <logic:equal name="caDelegationEditForm" property="matchedUser" value="-2">
          <bean:message bundle="appCommonRes" key="ca.error.delegation.multiplematch"/>
        </logic:equal>
        <logic:equal name="caDelegationEditForm" property="matchedUser" value="-3">
          <bean:message bundle="appCommonRes" key="ca.error.delegation.toself"/>
        </logic:equal>
      </div>
      
      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="add delegation form">
        <%-- hide the start time row if it is edit state and it is already started --%>
        <% boolean showStartDate = true; %>
        <logic:equal name="caDelegationEditForm" property="isNew" value="false">
          <logic:equal name="caDelegationEditForm" property="started" value="true">
             <% showStartDate = false; %>
          </logic:equal>
        </logic:equal>
        <% pageContext.setAttribute("showStartDate", showStartDate ? Boolean.TRUE: Boolean.FALSE); %> 
       
        
        <tr> 
          <logic:equal name="showStartDate" value="true">
            <td nowrap width="20%" class="label">
              <bean:message bundle="appCommonRes" key="ca.start"/>*:
            </td>  
            <td nowrap width="80%" class="labelField" colspan="4">
              <bvhtml:date name="caDelegationEditForm" property="start"/>
                <a href="JavaScript:datePopup('<html:rewrite   page="/cs/calendar.do"/>', 'caDelegationEditForm','start')"><img src="<%= request.getContextPath() %>/ca/images/icons/calendar.gif" border="0" align="absmiddle" alt="<bean:message key="cs.image.alt.calendar"/>" title="<bean:message key="cs.image.alt.calendar"/>"/></a>
                <html:hidden property="start.hour" value="0"/>
                <html:hidden property="start.minute" value="0"/>
                <html:hidden property="start.ind" value="0"/>
            </td>    
          </logic:equal>
          <logic:equal name="showStartDate" value="false">
            <td nowrap width="20%" class="label">
              <bean:message bundle="appCommonRes" key="ca.start"/>:
            </td>  
            <td nowrap width="80%" class="labelField" colspan="4">
              <bean:write name="caDelegationEditView" property="start" formatKey="format.datetime.medium" />
                <html:hidden property="start.year"/>
                <html:hidden property="start.month"/>
                <html:hidden property="start.day"/>
            </td>  
          </logic:equal>   
        </tr>
 
        <tr> 
          <td nowrap width="20%" class="label">
            <bean:message bundle="appCommonRes" key="ca.end"/>*:
          </td>
          <td nowrap width="80%" class="labelField" colspan="4">
              <bvhtml:date name="caDelegationEditForm" property="end"/>
              <a href="JavaScript:datePopup('<html:rewrite   page="/cs/calendar.do"/>', 'caDelegationEditForm','end')"><img src="<%= request.getContextPath() %>/ca/images/icons/calendar.gif" border="0" align="absmiddle" alt="<bean:message key="cs.image.alt.calendar"/>" title="<bean:message key="cs.image.alt.calendar"/>"/></a>
            <html:hidden property="end.hour" value="0"/>
            <html:hidden property="end.minute" value="0"/>
            <html:hidden property="end.ind" value="0"/>
          </td>  
        </tr>
        
        <tr> 
          <td class="label" width="10%">
            <bean:message bundle="appCommonRes" key="ca.reason"/>:
          </td>
          <td class="labelField" width="90%" colspan="4">
            <html:textarea property="description" cols="50" rows="6"/>
        </tr>
        
        <tr> 
          <logic:equal name="showStartDate" value="false">
            <td class="label" width="10%" nowrap>
              <bean:message bundle="appCommonRes" key="ca.delegateTo"/>:
            </td>
            <td class="labelField" width="10%">
              <bean:write name="caDelegationEditForm" property="fullName"/>
            </td>
            <td class="labelField" width="20%" colspan="2">
              (<bean:write name="caDelegationEditForm" property="userAlias"/>)
            </td>
          </logic:equal>
          <logic:equal name="showStartDate" value="true">
            <td class="label" width="10%" nowrap>
              <bean:message bundle="appCommonRes" key="ca.to"/>*:
            </td>
          <logic:equal name="caDelegationEditForm" property="isUsingFMLName" value="true">
            <td class="labelField" width="10%" nowrap>
              <html:text property="firstName" size="20" maxlength="80"/>
              <br><i>(<bean:message bundle="appCommonRes" key="ca.firstName"/>)</i>
            </td>
            <td class="labelField" width="10%" nowrap>
               <html:text property="lastName" size="20" maxlength="80"/>   
               <br><i>(<bean:message bundle="appCommonRes" key="ca.lastName"/>)</i>
            </td>
          </logic:equal>
          <logic:equal name="caDelegationEditForm" property="isUsingFMLName" value="false">
            <td class="labelField" width="10%" nowrap>
              <html:text property="fullName" size="20" maxlength="80"/>
              <br><i>(<bean:message bundle="appCommonRes" key="ca.fullName"/>)</i>
            </td>
          </logic:equal>
          <td class="labelField" width="10%" nowrap>
              <html:text property="userAlias" size="20" maxlength="80"/>
            <br><i>(<bean:message bundle="appCommonRes" key="ca.signInId"/>)</i>
          </td>
          <td class="labelField" width="10%" nowrap colspan="2">
            <input type="button" name="browse" class="pageButton" 
                   value='<bean:message bundle="appCommonRes" key="button.browse"/>'
                  onclick="searchUserPopup('<html:rewrite page="/ca/userSearch.do"/>','caDelegationEditForm')" /> 
          </td> 
          </logic:equal>
        </tr>  
    </table>
    
    <div class="pageButtonWrap" align="right">
      <html:reset styleClass="pageButton" property="resetBtn" titleKey="button.reset">
         <bean:message bundle="appCommonRes" key="button.reset"/>    
      </html:reset>       
                   
      <html:button styleClass="pageButton" property="cancelBtn"
                   titleKey="button.cancel" onclick="history.back()">
        <bean:message bundle="appCommonRes" key="button.cancel"/>
      </html:button>       
      <html:button styleClass="pageButton" property="saveBtn"  titleKey="button.save" 
                   onclick="onClickSave(this.form)">
        <bean:message bundle="appCommonRes" key="button.save"/>       
      </html:button>            
     </div>     
 
  </html:form>  
    </div>              
    </td>
  </tr>
</table>

<!--end zone 5 content here -->

<%-- </html:form> --%>
